package cn.iocoder.yudao.module.infrastructure.messy.controller.admin;

import cn.iocoder.yudao.framework.business.sse.pojo.SystemMessageUnreadType;
import cn.iocoder.yudao.framework.business.sse.service.SseService;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 *  这里是文件说明
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/03/15
 */
@Tag(name = "管理后台 - SSE")
@RestController
@RequestMapping("/infra/sse")
public class SseController {
    @Resource
    private SseService sseService;

    @GetMapping(value = "/subscribe", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public SseEmitter subscribe() {
        return sseService.subscribe();
    }

    @PostMapping(value = "/broadcast/demo")
    public CommonResult<SystemMessageUnreadType> systemMessageUnread() {
        SystemMessageUnreadType data = new SystemMessageUnreadType();
        data.setCount(1);
        sseService.broadcast(data);
        return success(data);
    }

}
